﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.SqlClient;

namespace BaoJian.ajax
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class SearchProductKeyWord : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request.QueryString["q"] == null)
            {
                return;
            }
            if (context.Request.QueryString["q"] != null)
            {
                string key = context.Request.QueryString["q"];
                string sql = "SELECT top 10 PName +'\n' AS PName FROM ExchangeProduct WHERE PName LIKE '%" + key + "%' ";               

                SqlDataReader dr = Maticsoft.DBUtility.DbHelperSQL.ExecuteReader(sql);
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                while (dr.Read())
                {
                    sb.Append(dr[0]);
                }
                dr.Close();
                context.Response.Write(sb.ToString());
            }
            else
            {
                string data = "";
                context.Response.Write(data);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
